package com.dries.portal.module.coupon.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/9/24 9:56
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum TemplateStatus {

    ON_LINE(1, "上架"),
    OFF_LINE(0, "下架"),
    ;

    /**
     * 优惠券分类编码
     */
    @EnumValue
    private Integer code;
    /**
     * 优惠券描述（分类）
     */
    private String desc;

    @JsonValue
    public String getDesc() {
        return desc;
    }

    /** 根据code获取到CouponStatus */
    public static TemplateStatus of(Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values()).filter(e -> e.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + "not exists!"));
    }

}
